package com.codeczx.mygeeknews;

import io.reactivex.Flowable;
import io.reactivex.processors.FlowableProcessor;
import io.reactivex.processors.PublishProcessor;

/**
 * Created by win10 on 2017/7/3.
 */

public class RxBus {

    private final FlowableProcessor<Object> bus;

    private RxBus(){
        // toSerialized()让onNext()等方法变成线程安全的
        bus = PublishProcessor.create().toSerialized();
    }

    private RxBus getDefault(){
        return RxBusHolder.sInstance;
    }

    private static class RxBusHolder{
        static final RxBus sInstance = new RxBus();
    }

    public void post(Object o){
        bus.onNext(o);
    }

    // 根据传入的 enterType 的类型返回特定类型的 被观察者
    public <T> Flowable<T> toFlowable(Class<T> enterType){
        bus.flatMap()
        return bus.ofType(enterType);
    }
}
